//
//  EOSRechargeViewController.m
//  CBT
//
//  Created by Mr.Zhang on 2018/12/18.
//  Copyright © 2018 Mr.Zhang. All rights reserved.
//

#import "EOSRechargeViewController.h"
#import "RechargeListViewController.h"
#import "UserManager.h"

@interface EOSRechargeViewController ()

@property (weak, nonatomic) IBOutlet UIBarButtonItem *rightBtn;
@property (weak, nonatomic) IBOutlet UILabel *memoInfoLabel;
@property (weak, nonatomic) IBOutlet UIButton *userAccountBtn;
@property (weak, nonatomic) IBOutlet UILabel *userAccountLabel;
@property (weak, nonatomic) IBOutlet UIButton *memoBtn;
@property (weak, nonatomic) IBOutlet UILabel *momeLabel;

@property (nonatomic, strong) NoDataView *noNetWorkView;

@property (nonatomic, copy) NSString *userAccountStr;

@end

@implementation EOSRechargeViewController

#pragma mark - VC Life

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startLoading];
    
    [self showInfos];
    
    [self getRecharge];
}

- (void)showInfos
{
    self.navigationItem.title = kLocalizedString(@"EOS充值", nil);
    self.rightBtn.title =  kLocalizedString(@"充值记录", nil);
    self.memoInfoLabel.text = kLocalizedString(@"MEMO为您的唯一识别码，谨防填错、漏填", nil);
    [self.userAccountBtn setTitle:kLocalizedString(@"复制", nil) forState:(UIControlStateNormal)];
    [self.memoBtn setTitle:kLocalizedString(@"复制", nil) forState:(UIControlStateNormal)];
    self.momeLabel.text = [NSString stringWithFormat:@"MEMO：%@",[CBTLocalUserManager sharedInstance].userId];
}

- (void)getRecharge
{
    @weak(self)

    [UserManager getUserDoRechargeWithUserId:[CBTLocalUserManager sharedInstance].userId coinId:self.coinId block:^(id data, HttpRequestResult result, NSString *msg) {
        [self_weak_ stopLoading];
        [self_weak_.noNetWorkView removeFromSuperview];
        if (result == kHttpRequestResultNormal) {
            self_weak_.userAccountStr = [data[@"data"]objectForKey:@"walletAddress"];
            self_weak_.userAccountLabel.text = [NSString stringWithFormat:@"%@%@",kLocalizedString(@"账号：", nil),[data[@"data"]objectForKey:@"walletAddress"]];
        }else{
            [HFStatusView showFailureMessage:kLocalizedString(@"网络异常，请稍后重试", nil)];
            [self_weak_.view addSubview:self_weak_.noNetWorkView];
        }
    }];
}

- (IBAction)rightBarButtonAction:(UIBarButtonItem *)sender {
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    RechargeListViewController *vc = [story instantiateViewControllerWithIdentifier:@"rechargeListVC"];
    vc.showListType = 0;
    vc.coinId = self.coinId;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)userAccountCopyClick:(UIButton *)sender {
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = self.userAccountStr;
    [HFStatusView showSuccessMessage:kLocalizedString(@"已复制到剪贴板",nil)];
}
- (IBAction)momoCopyClick:(UIButton *)sender {
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = [NSString stringWithFormat:@"%@",[CBTLocalUserManager sharedInstance].userId];
    [HFStatusView showSuccessMessage:kLocalizedString(@"已复制到剪贴板",nil)];
}

#pragma mark - Lazy

- (NoDataView *)noNetWorkView
{
    if (!_noNetWorkView) {
        @weak(self)
        _noNetWorkView = [[NoDataView alloc]initWithFrame:self.view.bounds type:(ShowType_NoNetWork) clickBlock:^{
            [self_weak_ startClearBgColorLoading];
            [self_weak_ getRecharge];
        }];
    }
    return _noNetWorkView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
